package org.itboys.kitchen.service.mongo.village;


import com.sun.org.apache.bcel.internal.generic.RETURN;
import org.apache.commons.lang3.StringUtils;
import org.itboys.commons.utils.tools.ListUtil;
import org.itboys.commons.utils.tools.LongUtil;
import org.itboys.kitchen.entity.mongo.village.KitchenVillage;
import org.itboys.kitchen.util.ChineseChangePinyi;
import org.itboys.mongodb.core.MongoDataSource;
import org.itboys.mongodb.service.BaseMongoService;
import org.itboys.param.PageResult;
import org.itboys.param.ParamUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * *作者：zzq
 * 时间：2017年5月8日
 * 描述：花果山（农厨）_市_小区_service
 *
 */
@Service
public class KitchenVillageService extends BaseMongoService<KitchenVillage> {
    @Resource(name = "kitchenDs")
    private MongoDataSource kitchenDataSource;
    @Override
    protected MongoDataSource getMongoDataSource() {
        return kitchenDataSource;
    }
    @Override
    protected Class<KitchenVillage> getEntityClass() {
        return KitchenVillage.class;
    }



    //查询小区
    public PageResult<KitchenVillage> select(HttpServletRequest request){
        Map<String,String> containsparam = ParamUtil.packageMongoVagueParam(request, "name","shopName","cityName","districtName","streetName");
        Map<String,Object> param = new HashMap<String,Object>();
        param.put("isDeleted",0);
        return super.containpageQuery(request,containsparam, param);
    }

    /**
     * 修改或新增
     * @param village
     */
    public void saveVillage(KitchenVillage village){
        String pyszm = ChineseChangePinyi.trans2PinYin(village.getName());
        village.setPyszm(pyszm);
        if(village.getId()==0l){
            super.save(village);
        }else{
            super.updateExceptEmpty(village.getId(),village);
        }
    }


    /**
     * 绑定门店
     * @param id
     * @param shopId
     * @param shopName
     */
    public void tieShop(Long id,Long shopId,String shopName){
        KitchenVillage village = new KitchenVillage();
        village.setId(id);
        village.setShopId(shopId);
        village.setShopName(shopName);
        super.updateExceptEmpty(id,village);
    }
    /**
     * 单个查询
     * @param id
     * @return
     */
    public KitchenVillage findOne(Long id) {
        KitchenVillage village = null;
        if (LongUtil.isNotZreo(id)) {
            village = super.getById(id);
        } else {
            village = new KitchenVillage();
            village.setId(id);
        }
        return village;
    }





}
